package Work07;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

/*请从控制台分别接收两个“生日”，格式为：yyyy年MM月dd日，用程序比较两个生日表示的人的年龄大小关系并打印出结果;

要求:

1:使用Date+SimpleDateFormat完成一遍,

2:再使用LocalDate+DateTimeFormatter+Period完成一遍;

提示:

注意,生日值越小,证明出生的越早,就意味着年龄越大,不要搞反了呦;
*/
public class birthday2 {
    public static void main(String[] args) throws ParseException {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入第一位同学的姓名");
        String name1=scanner.next();
        System.out.println("请输入第二位同学的姓名");
        String name2=scanner.next();
        System.out.println("请输入"+name1+"的生日");
        String birthday1=scanner.next();
        System.out.println("请输入"+name2+"的生日");
        String birthday2=scanner.next();
  method(birthday1,birthday2,name1,name2);
    }
    public static void method(String birthday1,String birthday2,String name1,String name2)throws ParseException {
        DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        LocalDate date = LocalDate.parse(birthday1,dateTimeFormatter);
        LocalDate date1= LocalDate.parse(birthday2,dateTimeFormatter);
        Period between = Period.between(date, date1);
if (date.isBefore(date1)){
    System.out.println(name1+"年龄更大");
}else{
    System.out.println(name2+"年龄更大");
}
    }
}
